package com.finstone.data.spider.eshop.pipeline;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

@Component
public class EShopGoodsDetailParamPipline extends BasePipeline {

	public void process(ResultItems paramResultItems, Task paramTask) {
		Map<String, Map<String, Object>> baseMap = paramResultItems.get("variables");

		String goods_id = paramResultItems.get("goods_id");

		for (Map.Entry<String, Map<String, Object>> entry : baseMap.entrySet()) {
			Map<String, Object> m = entry.getValue();

			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

			for (Map.Entry<String, Object> entry1 : m.entrySet()) {

				Map<String, Object> itemMap = new HashMap<String, Object>();

				itemMap.put("name1", entry.getKey());
				itemMap.put("name2", entry1.getKey());
				itemMap.put("value", entry1.getValue());
				itemMap.put("goods_id", goods_id);

				list.add(itemMap);
			}
			this.getNamedParameterJdbcTemplate().batchUpdate("insert into goods_params (goods_id,name1,name2,value) values (:goods_id,:name1,:name2,:value)",
					paramMapper(list));
		}
	}
}
